package com.itheima.tlias.tliasweb.filter;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@WebFilter(urlPatterns = "/*")
public class AbcFilter implements Filter {

    /**
     * 收到请求，每次都会执行
     * */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("----->AbcFilter doFilter， request uri:{}", ((HttpServletRequest)request).getRequestURI());
        // 放行到后端的接口
        chain.doFilter(request, response);
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("AbcFilter init 只会执行一次");
    }

    @Override
    public void destroy() {
        log.info("AbcFilter destroy 只会执行一次");
    }
}
